package command;

import java.util.ArrayList;

import Exceptions.TableNotFoundException;
import XMLProcessing.DatabaseProcessing;
import XMLProcessing.TableProcessing;

public class DeleteStatement implements IStatement {
	private String table_name;
	private ConditionNode c;
	
	public DeleteStatement(String table_name,ConditionNode c) {
		this.table_name = table_name;
		this.c = c;
	}
	
	public DeleteStatement(String table_name) {
		this.table_name = table_name;
		this.c = null;
	}
	
	public String toString() {
		String a =  "Delete FROM" + table_name + " WHERE";
		a += c;
		return a;
	}

	@Override
	public ResultNode eval() throws TableNotFoundException {
		String xmlFile = DatabaseProcessing.retrieveTable(this.table_name);
		ResultNode rN = null;
		Integer a = TableProcessing.deleteTable(xmlFile,this.c);
		rN = new ResultNode(null,null,a);
		return rN;
	}
}
